package blocksim.hash;

import java.security.NoSuchAlgorithmException;

public abstract class HashStrategyFactory {

  public static int DEFAULT_RABIN_DEGREE = 53; // Maximum degree allowed by this implementation
  public static String RABIN_WINDOWED = RabinHashStrategy.STRATEGY_ID;
  public static String RABIN_NOT_WINDOWED = NotWindowedRabinHashStrategy.STRATEGY_ID;
  public static String SHA = "SHA";
  public static String MD5 = "MD5";

  public static HashStrategy getInstance(String algorithm, int windowSize)
      throws NoSuchAlgorithmException {
    if (algorithm.equals(RABIN_WINDOWED)) {
      return new RabinHashStrategy(windowSize, DEFAULT_RABIN_DEGREE);
    } else if (algorithm.equals(RABIN_NOT_WINDOWED)) {
      return new NotWindowedRabinHashStrategy(windowSize);
    }
    return new MessageDigestHashStrategy(windowSize, algorithm);
  }
}
